/**
 * 添加或者修改页面
 */
var HxBasicGoodsInfoDlg = {
    data: {
        id:"",
        goodsCustomerId: "",
        goodsCustomerName: "",
        goodsName: "",
        goodsNumber: "",
        goodsPcode69: "",
        goodsXcode69: "",
        goodsHelpcode: "",
        goodsSpecs: "",
        goodsBigtype: "",
        goodsBrand: "",

        jibenUnit: "",
        kcUnit: "",
        kcRate: "",
        cgUnit: "",
        cgRate: "",
        pfUnit: "",
        pfRate: "",
        psUnit: "",
        psRate: "",

        anquanNum: "",
        goodsBottom: "",
        goodsLamination: "",
        goodsTraylayer: "",
        goodsSupportvolume: "",
        length: "",
        height: "",
        width: "",
        goodsWeight: "",
        goodsVolume: "",
        goodsChargingCg: "",
        goodsChargingPs: "",
        goodsChargingPf: "",
        goodsWarranty: ""
    }
};
var BasicPutgoodsInfoDlg = {
    data: {
        id:"",
        dictId:"",
        putgoodsCustomerId: "",
        putgoodsOperateName: "",
        putgoodsName: "",
    }
};
/**
 * 添加或者修改页面
 */
var BasicPositionInfoDlg = {
    data: {
    	id: "",
        positionNumber: "",
        positionAreaId: ""
    }
};
layui.use(['form', 'admin', 'ax', 'laydate'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    var laydate = layui.laydate;
    //让当前iframe弹层高度适应
    admin.iframeAuto();

    //渲染时间
    laydate.render({
        elem: '#detailedDate' //生产日期
    });

    //查询库区
    /*form.on('select(warehouseId)',function(){
        $("#areaId").empty();
        $.ajax({
            url:Feng.ctxPath + '/basicArea/Querylist',
            dataType:"json",   //返回格式为json
            async: false,
            data:{"areaWarehouseId":$("#warehouseId").val()},    //参数值
            type:"post",   //请求方式
            success:function(data){
                if(data.length>0){
                    var str = "<option value=''>请选择</option>";
                    $.each(data,function(key,value){
                        str += "<option value='"+value.id+"'>"+value.areaNumber+"</option>";
                    });
                    $("#areaId").html(str);
                }
            }
        });
        form.render('select');
    });*/

    //查询库位
    /*form.on('select(areaId)',function(){
        $("#positionId").empty();
        $.ajax({
            url:Feng.ctxPath + '/basicPosition/Querylist',
            dataType:"json",   //返回格式为json
            async: false,
            data:{"positionAreaId":$("#areaId").val()},    //参数值
            type:"post",   //请求方式
            success:function(data){
                if(data.length>0){
                    var str = "<option value=''>请选择</option>";
                    $.each(data,function(key,value){
                        str += "<option value='"+value.id+"'>"+value.positionNumber+"</option>";
                    });
                    $("#positionId").html(str);
                }
            }
        });
        form.render('select');
    });*/
    
    $('#choicePosition').click(function () {
    	var warehouseId = $("#warehouseId").val();
    	if (warehouseId==null||warehouseId=='') {
    		layer.msg('请选择仓库'); 
		} else {
	        layer.open({
	            type: 2,
	            title: '选择转入库位',
	            area: ['1000px', '500px'],
	            content: Feng.ctxPath + '/basicPosition/tochoicePositionHx?warehouseId='+warehouseId,
	            end: function () {
	                $("#positionId").val(BasicPositionInfoDlg.data.id);
	                $("#positionNumber").val(BasicPositionInfoDlg.data.positionNumber);
	                $("#areaId").val(BasicPositionInfoDlg.data.positionAreaId);
	            }
	        });
		}
    });

    //点击商品名称
    $("#choiceGoods").click(function(){
        layer.open({
            type: 2,
            title: '选择商品',
            area: ['1000px', '500px'],
            content: Feng.ctxPath + '/hxBasicGoods/toChoiceGoods',
            end: function () {
                $("#goodsId").val(HxBasicGoodsInfoDlg.data.id);//商品id
                $("#goodsName").val(HxBasicGoodsInfoDlg.data.goodsName);//商品名称
                $("#goodsNumber").val(HxBasicGoodsInfoDlg.data.goodsNumber);//商品编号
            }
        });
    });
    
    //选择发货客户
    $('#setUnit').click(function () {
        layer.open({
            type: 2,
            title: '发货客户',
            area: ['1000px', '500px'],
            content: Feng.ctxPath + '/basicPutgoods/tochoiceBasicPutgoods_hx',
            end: function () {
                $("#setUnitId").val(BasicPutgoodsInfoDlg.data.id);
                $("#setUnit").val(BasicPutgoodsInfoDlg.data.putgoodsName);
            }
        });
    });
    
    //重置发货客户
    $('#reset').click(function () {
        $("#setUnitId").val("");
        $("#setUnit").val("");
    });

    //表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var ajax = new $ax(Feng.ctxPath + "/hxStorageStock/addItem", function (data) {
            if (data.success){
                Feng.success("添加成功！");
                window.location.href = Feng.ctxPath + '/hxStorageStock'
            } else {
                Feng.error("添加失败！" + data.message)
            }
        }, function (data) {
            Feng.error("添加失败！" + data.responseJSON.message)
        });
        ajax.set(data.field);
        ajax.start();
        return false;
    });

    //返回按钮
    $("#backupPage").click(function () {
        window.location.href = Feng.ctxPath + '/hxStorageStock'
    });

});